package q2d.common.models;

import java.io.Serializable;

import q2d.common.models.units.PlayerHit;
import q2d.common.models.units.WallHit;


public class HitsContainer implements Serializable {
        
        private int playersHitsArray[];
        private float wallHitsArray[];
        transient private int currentPlayersHitsCount;
        transient private int currentWallHitsCount;
        

        public HitsContainer(final int players_hits_count, final int wall_hits_count){
        	// trafienia
        	playersHitsArray = new int[players_hits_count*2];
        	wallHitsArray = new float[wall_hits_count*4];
                
            // liczniki pozycji w tablicach
        	currentPlayersHitsCount= 0;
        	currentWallHitsCount= 0;
        }


        /**
         * Dodaje trafienie w gracza.
         * @param player_hit
         */
        public void addPlayerHit(PlayerHit player_hit){
        	playersHitsArray[currentPlayersHitsCount++] = player_hit.x;
        	playersHitsArray[currentPlayersHitsCount++] = player_hit.y;
        }


        /**
         * Zwraca trafienie w gracza.
         * @param player_hit
         */
        public PlayerHit getPlayerHit(int i){
        	return new PlayerHit((int)playersHitsArray[i*2], (int)playersHitsArray[i*2+1]);
        }


        /**
         * Zwraca liczbe trafien w gracza.
         * @param player_hit
         */
        public int getPlayerHitsCount(){
                return playersHitsArray.length/2;
        }


        /**
         * Dodaje trafienie w sciane.
         * @param wall_hit
         */
        public void addWallHit(WallHit wall_hit){
        	wallHitsArray[currentWallHitsCount++] = wall_hit.x;
        	wallHitsArray[currentWallHitsCount++] = wall_hit.y;
        	wallHitsArray[currentWallHitsCount++] = (float)wall_hit.vx;
        	wallHitsArray[currentWallHitsCount++] = (float)wall_hit.vy;
        }


        /**
         * Zwraca trafienie w sciane.
         */
        public WallHit getWallHit(int i){
        	return new WallHit((int)wallHitsArray[i*4], (int)wallHitsArray[i*4+1], (double)wallHitsArray[i*4+2], (double)wallHitsArray[i*4+3]);
        }


        /**
         * Zwraca liczbe trafien w sciane.
         */
        public int getWallHitsCount(){
        	return wallHitsArray.length/4;
        }
}